package org.op.looks;

import java.util.HashMap;
import java.util.Map;

import javax.swing.JOptionPane;

import org.op.FrameView;
import org.op.service.config.ConfigKeys;
import org.op.service.config.ConfigurationService;
import org.op.service.log.LoggerService;
import org.op.service.ui.UiService;
import org.op.util.MessageController;

public class TattooThemeControllerImpl implements SkinController {

	private FrameView frameView;
	private ConfigurationService configService;
	private UiService uiService;
	private MessageController messageController;
	private LoggerService logger;
	
	private Map<String, String> initThemeMap() {
		Map<String, String> themeMap = new HashMap<String, String>();
		
		themeMap.put("Acryl", "com.jtattoo.plaf.acryl.AcrylLookAndFeel");
		themeMap.put("Aero", "com.jtattoo.plaf.aero.AeroLookAndFeel");
		themeMap.put("Aluminum", "com.jtattoo.plaf.aluminium.AluminiumLookAndFeel");
		themeMap.put("Bernstein", "com.jtattoo.plaf.bernstein.BernsteinLookAndFeel");
		themeMap.put("Fast", "com.jtattoo.plaf.fast.FastLookAndFeel");
		themeMap.put("Hifi", "com.jtattoo.plaf.hifi.HiFiLookAndFeel");
		themeMap.put("Luna", "com.jtattoo.plaf.luna.LunaLookAndFeel");
		themeMap.put("McWin", "com.jtattoo.plaf.mcwin.McWinLookAndFeel");
		themeMap.put("Mint", "com.jtattoo.plaf.mint.MintLookAndFeel");
		themeMap.put("Noire", "com.jtattoo.plaf.noire.NoireLookAndFeel");
		themeMap.put("Smart", "com.jtattoo.plaf.smart.SmartLookAndFeel");
		
		return themeMap;
	}
	
	public void configureSkin() {

		try {
			Map<String, String> themeMap = initThemeMap();
			Object[] choices = themeMap.keySet().toArray();
			
			String existingTheme = configService.getProperty(ConfigKeys.KEY_SKIN);
			
			String question = messageController.getMessage("set.skin.question");
			String label = messageController.getLabel("set.skin.popup.title");
			
			String choice = (String)JOptionPane.showInputDialog(
			                    frameView.getFrame(),
			                    question,
			                    label,
			                    JOptionPane.PLAIN_MESSAGE,
			                    null,
			                    choices,
			                    existingTheme);
			
			if (choice!=null) {
				String laf = themeMap.get(choice);
				configService.updateProperty(ConfigKeys.KEY_LOOK_AND_FEEL, laf);
				configService.updateProperty(ConfigKeys.KEY_SKIN, choice);
				uiService.configureUI();
				String message = messageController.getMessage("theme.available.restart");
				frameView.showInfoDialog(message);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public FrameView getFrameView() {
		return frameView;
	}

	public void setFrameView(FrameView frameView) {
		this.frameView = frameView;
	}

	public ConfigurationService getConfigService() {
		return configService;
	}

	public void setConfigService(ConfigurationService configService) {
		this.configService = configService;
	}

	public UiService getUiService() {
		return uiService;
	}

	public void setUiService(UiService uiService) {
		this.uiService = uiService;
	}

	public MessageController getMessageController() {
		return messageController;
	}

	public void setMessageController(MessageController messageController) {
		this.messageController = messageController;
	}

	public LoggerService getLogger() {
		return logger;
	}

	public void setLogger(LoggerService logger) {
		this.logger = logger;
	}

}
